package net;

import java.io.IOException;
import java.net.SocketException;
import java.util.logging.Level;

import model.Settings;
import model.contents.Content;

import org.apache.commons.net.ftp.FTPClient;

import util.LoggingUtils;

public class FTPDownloader implements Downloader {

	// singleton instance
	private static FTPDownloader	_instance;

	// private FTPClient ftp;
	private boolean					override;

	@Override
	public boolean download(String remotePath, String localPath) {
		FTPClient client = new FTPClient();
		final String classMethod = "FTPDownloader .download(String remotePath, String localPath)";
		try {
			client.connect(Settings.WEBTOOL_FTP_HOST);
			System.out.println(client.getReplyString());
			client.login(Settings.WEBTOOL_FTP_USERNAME, Settings.WEBTOOL_FTP_PASSWORD);
			System.out.println(client.getReplyString());
			client.disconnect();
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			LoggingUtils.log(Level.SEVERE, "Error in FTPDownloader "+classMethod,e);
			//e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			LoggingUtils.log(Level.SEVERE, "Error in FTPDownloader "+classMethod,e);
			//e.printStackTrace();
		}
		catch (NullPointerException e) {
			// TODO Auto-generated catch block
			LoggingUtils.log(Level.SEVERE, "Error in FTPDownloader "+classMethod,e);
			//e.printStackTrace();
		}
		return false;
	}

	@Override
	public void setOverride(boolean overrideExistingFile) {
		this.override = overrideExistingFile;
	}

	@Override
	public boolean isOverride() {
		return this.override;
	}

	public static FTPDownloader getInstance() {
		if (_instance == null) {
			_instance = new FTPDownloader();
		}
		return _instance;
	}

	private FTPDownloader() {
	}

	@Override
	public void addDownload(Content c) {
		// TODO Auto-generated method stub

	}
}
